/**
 * Created by way on 16/9/17.
 */

const $ = require('../lib/kdom');
import cfg from '../config';
import { get, post, getView } from '../util/api';
import { formatDate } from '../util/formatDate';
import { dateStr } from '../util/tool';
import * as ajax from '../lib/kajax';
import { urlParam } from '../lib/kutil';
let _view = require('raw-loader!./deltail.html'); // eslint-disable-line
// let _view = '';

let issueId = null; // 工单的id
let status = {
  "0": "",
  "1": "处理中",
  "2": "已完成",
  "3": "未处理",
};
export default class {
  path = '/ogs/deltail$';
  hash = '/ogs/deltail';
  title = '详情';

  constructor(opt) {
    opt = opt || {};
    this.path = opt.path || this.path;
    this.hash = opt.hash || this.hash;
    this.title = opt.title || this.title;
  }

  // 输出视图
  view(cb) {
    if (!_view) {
      // 静态资源浏览器有缓存,增加时标,强制刷新!
      getView(`${cfg.ogs.view.host}${cfg.ogs.view.deltail}?t=${(+new Date())}`, '', (rs) => {
        _view = rs;
        cb(null, _view);
      });
    } else
      cb(null, _view);
  }

  // 在已经加载的视图上操作
  bind(dv, params) {
    console.log('我是详情', params);
    listDeltailFun(params);

    delBack.onclick = () => {
      $.router.go('/ogs/list', params, true);
    };

    delBack.onclick = () => {
      $.router.go('/ogs/list', params, true);
    };
  }
}

function listDeltailFun(data) {
  if (!data) return;
  let issueInfo = data.issueInfo;
  let userInfo = data.userInfo;
  let rc = '';
  rc = `<div class="card">
    <div class="card-header" onclick="window.location.href='${issueInfo.company[0].url}'"><span>${issueInfo.company[0].name}</span><span class="icon icon-right"></span></div>
    <div class="card-content">
      <div class="list-block media-list" style="margin:0;">
        <ul>
          <li class="item-content">
            <div class="item-media">
              <img src="${issueInfo.company[0].logo}"
                width="44">
            </div>
            <div class="item-inner">
              <div class="item-title-row">
                <div class="item-title">${issueInfo.title}</div>
              </div>
              <div class="item-subtitle">${issueInfo.text}</div>
            </div>
          </li>
        </ul>
      </div>
    </div>
   <div class="card-footer">
      <span>${formatDate('yyyy-MM-dd hh:mm', issueInfo.createTime)}</span>
      <span>${status[issueInfo.status]}</span>
    </div>
    `;
  $.html(listDeltail, rc);
}